package com.ruoyi.project.business.pickCode.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.pickCode.domain.OutPickCode;
import com.ruoyi.project.business.pickCode.domain.YlPickCode;
import com.ruoyi.project.business.pickCode.service.IYlPickCodeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 取货码Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@Controller
@RequestMapping("/business/pickCode")
public class YlPickCodeController extends BaseController
{
    private String prefix = "business/pickCode";

    @Autowired
    private IYlPickCodeService ylPickCodeService;

    @RequiresPermissions("business:pickCode:view")
    @GetMapping()
    public String pickCode()
    {
        return prefix + "/pickCode";
    }

    /**
     * 查询取货码列表
     */
    @RequiresPermissions("business:pickCode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlPickCode ylPickCode)
    {
        startPage();
        List<YlPickCode> list = ylPickCodeService.selectYlPickCodeList(ylPickCode);
        return getDataTable(list);
    }

    /**
     * 导出取货码列表
     */
    @RequiresPermissions("business:pickCode:export")
    @Log(title = "取货码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlPickCode ylPickCode)
    {
        List<YlPickCode> list = ylPickCodeService.selectYlPickCodeList(ylPickCode);
        ExcelUtil<YlPickCode> util = new ExcelUtil<YlPickCode>(YlPickCode.class);
        return util.exportExcel(list, "取货码数据");
    }

    /**
     * 新增取货码
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存取货码
     */
    @RequiresPermissions("business:pickCode:add")
    @Log(title = "取货码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlPickCode ylPickCode)
    {
        return toAjax(ylPickCodeService.insertYlPickCode(ylPickCode));
    }

    /**
     * 修改取货码
     */
    @GetMapping("/edit/{pickId}")
    public String edit(@PathVariable("pickId") Long pickId, ModelMap mmap)
    {
        YlPickCode ylPickCode = ylPickCodeService.selectYlPickCodeById(pickId);
        mmap.put("ylPickCode", ylPickCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存取货码
     */
    @RequiresPermissions("business:pickCode:edit")
    @Log(title = "取货码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlPickCode ylPickCode)
    {
        return toAjax(ylPickCodeService.updateYlPickCode(ylPickCode));
    }

    /**
     * 删除取货码
     */
    @RequiresPermissions("business:pickCode:remove")
    @Log(title = "取货码", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylPickCodeService.deleteYlPickCodeByIds(ids));
    }
    
    /**
     * 停用取货码
     */
    @RequiresPermissions("business:pickCode:block")
    @Log(title = "取货码", businessType = BusinessType.DELETE)
    @PostMapping( "/block")
    @ResponseBody
    public AjaxResult block(String ids)
    {
        return toAjax(ylPickCodeService.blockYlPickCodeByIds(ids));
    }
    
    /**
     * 启用取货码
     */
    @RequiresPermissions("business:pickCode:block")
    @Log(title = "取货码", businessType = BusinessType.DELETE)
    @PostMapping( "/active")
    @ResponseBody
    public AjaxResult active(String ids)
    {
        return toAjax(ylPickCodeService.activeYlPickCodeByIds(ids));
    }
    
    /**
     * 验证取货码
     */
    @Log(title = "取货码", businessType = BusinessType.UPDATE)
    @PostMapping( "/public/validate")
    @ResponseBody
    public String validate(OutPickCode outPickCode)
    {
    	String machineId = outPickCode.getMachid();
    	Long pickCode = outPickCode.getPickcode();
        return ylPickCodeService.validatePickCode(machineId,pickCode);
    }
}
